package com.andaily.domain.account;

import com.andaily.domain.AbstractDomain;
import com.andaily.domain.dto.account.AccountTypeDTO;
import com.andaily.domain.shared.Application;
import com.andaily.domain.shared.MobileStyle;
import com.andaily.domain.user.User;

/**
 * @author Shengzhao Li
 */
public class AccountType extends AbstractDomain {

    private String name;
    /**
     * You can think description is category
     */
    private String description;
    private int usedTimes;
    /**
     * If it it default type, do not edit or delete
     */
    private boolean defaultType;

    /**
     * If the type is default, owner is null.
     */
    private User owner;

    /**
     * Define the type is daily or not .
     */
    private boolean daily = true;

    /**
     * True is mean anyone can see the Account information,
     * False is mean only self can see,after login.
     * Default is true.
     */
    private boolean publicity = true;
    //Custom type style,default c
    private MobileStyle style = MobileStyle.defaultStyle();

    public AccountType() {
    }

    public AccountType(String name, String description, boolean defaultType) {
        this.name = name;
        this.description = description;
        this.defaultType = defaultType;
    }

    public String name() {
        return name;
    }

    public String description() {
        return description;
    }

    public int usedTimes() {
        return usedTimes;
    }

    public boolean defaultType() {
        return defaultType;
    }

    public User owner() {
        return owner;
    }

    public boolean daily() {
        return daily;
    }

    public boolean publicity() {
        return publicity;
    }

    public void update(User owner, boolean daily, boolean publicity) {
        this.owner = owner;
        this.daily = daily;
        this.publicity = publicity;
    }

    public void updateByDTO(AccountTypeDTO accountTypeDTO) {
        this.name = accountTypeDTO.getName();
        this.description = accountTypeDTO.getDescription();
        this.daily = accountTypeDTO.isDaily();
        this.publicity = accountTypeDTO.isPublicity();
        this.style = accountTypeDTO.getStyle();
    }

    public boolean isIncome() {
        return this.guid().equals(Application.incomeAccountTypeGuid());
    }

    public MobileStyle style() {
        return style;
    }

    public void updateStyle(MobileStyle style) {
        this.style = style;
    }
}
